package com.fowo.api.common.query;

import cn.hutool.core.util.StrUtil;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import lombok.experimental.FieldNameConstants;

import java.io.Serializable;

@Data
@Accessors(chain = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
@Builder
@NoArgsConstructor
@AllArgsConstructor
@FieldNameConstants
public class QueryCondition implements Serializable {

    private static final long serialVersionUID = 4740166316629191651L;

    private String field;
    /**
     * 组件的类型（例如：input、select、radio）
     */
    private String type  = "input";
    /**
     * 对应的数据库字段的类型
     * 支持：int、bigDecimal、short、long、float、double、boolean
     */
    private String dbType = "String";
    private String rule;
    private String val;

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        if (field == null || "".equals(field)) {
            return "";
        }
        sb.append(this.field).append(" ").append(this.rule).append(" ").append(this.type).append(" ").append(this.dbType).append(" ").append(this.val);
        return sb.toString();
    }


    public static boolean isEmpty(Object object) {
        if (object == null) {
            return (true);
        }
        if ("".equals(object)) {
            return (true);
        }
        if (StrUtil.NULL.equals(object)) {
            return (true);
        }
        return (false);
    }

    public static boolean isNotEmpty(Object object) {
        if (object != null && !"".equals(object) && !object.equals(StrUtil.NULL)) {
            return (true);
        }
        return (false);
    }

}
